package cn.sc.summer.calculate.controller;

import cn.sc.summer.calculate.checkgroup.ValidatedGroup;
import cn.sc.summer.calculate.form.*;
import cn.sc.summer.calculate.service.TaskService;
import cn.sc.summer.calculate.vo.DefinedTaskInfoVO;
import cn.sc.summer.calculate.vo.TaskInfoVO;
import cn.sc.summer.constant.model.PageResult;
import cn.sc.summer.constant.model.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 类名：定时任务管理控制层
 *
 * @author a-xin
 * @date 2023/11/27 08:17
 */
@Slf4j
@RestController
@RequestMapping("/task")
@Api(tags = "task-定时任务管理控制层")
public class TaskController {

    @Resource
    private TaskService taskService;

    @PostMapping("/addTaskInfo")
    @ApiOperation(value = "新增定时任务")
    public Result<TaskInfoVO> addTaskInfo(@Validated(ValidatedGroup.ADD_TASK_INFO.class) @RequestBody TaskInfoForm form) {
        return Result.success(taskService.addTaskInfo(form));
    }

    @PostMapping("/updateTaskInfo")
    @ApiOperation(value = "更新定时任务信息")
    public Result<TaskInfoVO> updateTaskInfo(@Validated(ValidatedGroup.UPDATE_TASK_INFO.class) @RequestBody TaskInfoForm form) {
        return Result.success(taskService.updateTaskInfo(form));
    }

    @GetMapping("/deleteTaskInfo")
    @ApiOperation(value = "删除定时任务")
    public Result<String> deleteTaskInfo(@RequestParam("taskId") String taskId) {
        taskService.deleteTaskInfo(taskId);
        return Result.success();
    }

    @PostMapping("/getTaskInfo")
    @ApiOperation(value = "分页获取定时任务")
    public Result<PageResult<TaskInfoVO>> getTaskInfo(@Validated @RequestBody GetTaskInfoForm form) {
        return Result.success(taskService.getTaskInfo(form));
    }

    @PostMapping("/getDefinedTaskInfo")
    @ApiOperation(value = "分页获取已定义的定时任务")
    public Result<PageResult<DefinedTaskInfoVO>> getDefinedTaskInfo(@Validated @RequestBody DefinedTaskInfoForm form) {
        return Result.success(taskService.getDefinedTaskInfo(form));
    }

    @PostMapping("/operationTask")
    @ApiOperation(value = "操作定时任务")
    public Result<String> operationTask(@Validated @RequestBody OperationTaskForm form) {
        taskService.operationTask(form);
        return Result.success();
    }

    @PostMapping("/updateTask")
    @ApiOperation(value = "更新定时任务")
    public Result<String> updateTask(@Validated @RequestBody UpdateTaskForm form) {
        taskService.updateTask(form);
        return Result.success();
    }

}
